<template>
  <div>
    <imp-info :fields="fields" @toSubmit="toSubmit"/>
  </div>
</template>

<script>
import impInfo from '@/components/impInfo'
import api from '@/api'
export default {
  name: 'teacher-imp-info',
  data () {
    return {
      fields: [
        {label: '姓名(真实姓名)', key: 'name', type: 'input'},
        {label: '身份证号码', key: 'identity', type: 'input'},
        {label: '所在城市', key: 'location', type: 'address'}
      ]
    }
  },
  methods: {
    toSubmit (params) {
      let formData = new FormData()
      formData.append('id', JSON.parse(sessionStorage.getItem('user')).id)
      // formData.append('id', '1')
      Object.keys(params).forEach(key => {
        if (params[key]) {
          formData.append(key, params[key])
        }
      })
      api.teacherPerfectIndividual({
        params: formData,
        callback: res => {
          if (!res.error) {
            this.getUserInfo()
          }
        }
      })
    },

    // 获取用户信息
    getUserInfo () {
      let params = {
        token: localStorage.getItem('teacher_token')
      }
      api.teacherPersonal({
        params,
        callback: res => {
          if (res.data.error_code === 0) {
            window.sessionStorage.setItem('user', JSON.stringify(res.data.data))
            this.$store.commit('SET_TEACHER', res.data.data)
            this.$router.push('/my/index')
          }
        }
      })
    }
  },
  components: {
    impInfo
  },
  created () {
  }
}
</script>

<style scoped>

</style>
